package cn.com.demo.service.imp;

import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.stereotype.Service;

import cn.com.common.dao.IBaseDao;
import cn.com.common.pagination.Page;
import cn.com.common.pagination.PageUtil;
import cn.com.common.service.imp.BaseService;
import cn.com.demo.dao.TsTourGuideDao;
import cn.com.demo.pojo.TsTourGuide;
import cn.com.demo.service.TsTourGuideService;

@Service("TsTourGuideService")
public class TsTourGuideServiceImpl extends BaseService<TsTourGuide, Integer>
		implements TsTourGuideService {
	private static final Logger LOGGER = LoggerFactory
			.getLogger(TsTourGuideServiceImpl.class);

	private TsTourGuideDao tsTourGuideDao;

	@Autowired
	@Qualifier("TsTourGuideDao")
	@Override
	public void setBaseDao(IBaseDao<TsTourGuide, Integer> tsTourGuideDao) {
		// TODO Auto-generated method stub
		this.baseDao = tsTourGuideDao;
		this.tsTourGuideDao = (TsTourGuideDao) tsTourGuideDao;
	}

	@Override
	public TsTourGuide checkGuidePassword(String userKey, String password) {
		// TODO Auto-generated method stub
		return tsTourGuideDao.checkGuidePassword(userKey, password);
	}

	@Override
	public Page<TsTourGuide> query(int pn, int pageSize, TsTourGuide command) {
		return PageUtil.getPage(tsTourGuideDao.countQuery(command), pn,
				tsTourGuideDao.query(pn, pageSize, command), pageSize);
	}

	@Override
	public List<TsTourGuide> findByProperty(String propertyName, Object value) {
		// TODO Auto-generated method stub
		return tsTourGuideDao.findByProperty(propertyName, value);
	}
	/**
	 * 负责将方法的返回值加入到缓存中
	 * value：缓存位置名称，不能为空，如果使用ehcache，就是ehcache.xml中声明的cache的name
	 * key：缓存的key，默认为空，既表示使用方法的参数类型及参数值作为key
	 */
	@Cacheable(value = "andCache", key = "'TsTourGuideService-print-id-'+#id ")
	public void print(int id) {
		System.out.println(id);
	}

	@CacheEvict(value = "andCache", allEntries = true)
	public void clearCache() {
		System.out.println("清空緩存");
	}
	

}